<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册——校园技能互助平台</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Poppins', sans-serif;
        }

        body {
            overflow: hidden;
            background: linear-gradient(to bottom, #f1f4f9, #dff1ff);
        }

        #app {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }

        .color {
            position: absolute;
            filter: blur(150px);
        }

        .color:nth-child(1) {
            top: -350px;
            width: 600px;
            height: 600px;
            background: #7d9cff; /* 更浅的蓝色 */
        }

        .color:nth-child(2) {
            bottom: -150px;
            left: 100px;
            width: 500px;
            height: 500px;
            background: #ff9d9d; /* 更浅的红色 */
        }

        .color:nth-child(3) {
            bottom: 50px;
            right: 100px;
            width: 500px;
            height: 500px;
            background: #66e0ff; /* 更浅的蓝色 */
        }

        .box {
            position: relative;
        }

        .square {
            position: absolute;
            backdrop-filter: blur(5px);
            box-shadow: 0 25px 45px rgba(0, 0, 0, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.5);
            border-right: 1px solid rgba(255, 255, 255, 0.2);
            border-bottom: 1px solid rgba(255, 255, 255, 0.2);
            background: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
            animation: animate 10s linear infinite;
            animation-delay: calc(-1s * var(--i));
        }

        @keyframes animate {
            0%, 100% {
                transform: translateY(-40px);
            }
            50% {
                transform: translateY(40px);
            }
        }

        .square:nth-child(1) {
            top: -50px;
            right: -60px;
            width: 100px;
            height: 100px;
        }

        .square:nth-child(2) {
            top: 150px;
            left: -100px;
            width: 120px;
            height: 120px;
            z-index: 2;
        }

        .square:nth-child(3) {
            bottom: 50px;
            right: -60px;
            width: 80px;
            height: 80px;
            z-index: 2;
        }

        .square:nth-child(4) {
            bottom: -80px;
            left: 100px;
            width: 50px;
            height: 50px;
        }

        .square:nth-child(5) {
            top: -90px;
            left: 140px;
            width: 60px;
            height: 60px;
        }

        .container {
            position: relative;
            width: 400px;
            min-height: 500px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
            display: flex;
            justify-content: center;
            align-items: center;
            backdrop-filter: blur(5px);
            box-shadow: 0 25px 45px rgba(0, 0, 0, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.5);
            border-right: 1px solid rgba(255, 255, 255, 0.2);
            border-bottom: 1px solid rgba(255, 255, 255, 0.2);
        }

        .form {
            position: relative;
            height: 100%;
            width: 100%;
            padding: 40px;
        }

        .form h2 {
            position: relative;
            color: #333;
            font-size: 24px;
            font-weight: 600;
            letter-spacing: 1px;
            margin-bottom: 40px;
        }

        .form h2::before {
            content: '';
            position: absolute;
            left: 0;
            bottom: -10px;
            width: 80px;
            height: 4px;
            background: #333;
        }

        .inputBox {
            width: 100%;
            margin-top: 15px;
        }

        .inputBox input {
            width: 100%;
            background: rgba(255, 255, 255, 0.7);
            border: none;
            outline: none;
            padding: 10px 20px;
            border-radius: 35px;
            border: 1px solid rgba(255, 255, 255, 0.5);
            border-right: 1px solid rgba(255, 255, 255, 0.2);
            border-bottom: 1px solid rgba(255, 255, 255, 0.2);
            font-size: 16px;
            letter-spacing: 1px;
            color: #333;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        }

        .inputBox input::placeholder {
            color: #666;
        }

        .inputBox input[type="submit"] {
            background: #fff;
            color: #666;
            max-width: 100px;
            cursor: pointer;
            margin-bottom: 10px;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .inputBox input[type="submit"]:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            background: #7d9cff; /* 使用更浅的蓝色 */
            color: white;
        }

        .forget {
            margin-top: 5px;
            color: #666;
        }

        .forget a {
            color: #444;
            font-weight: 600;
            text-decoration: none;
            transition: all 0.3s ease;
        }

        .forget a:hover {
            text-decoration: underline;
            color: #7d9cff; /* 使用更浅的蓝色 */
        }

        .error-message {
            color: #ff9d9d; /* 使用更浅的红色 */
            font-size: 14px;
            margin-top: 5px;
            margin-left: 20px;
        }

        .success-message {
            color: #66e0ff; /* 使用更浅的蓝色 */
            font-size: 14px;
            margin-top: 10px;
            text-align: center;
            font-weight: 500;
        }

        .remember {
            display: flex;
            align-items: center;
            margin-top: 10px;
            color: #666;
        }

        .remember input {
            margin-right: 8px;
        }
        
        .agreement {
            display: flex;
            align-items: center;
            margin-top: 15px;
            color: #666;
            font-size: 14px;
        }
        
        .agreement input {
            margin-right: 8px;
        }
        
        .agreement a {
            color: #7d9cff; /* 使用更浅的蓝色 */
            text-decoration: none;
        }
        
        .agreement a:hover {
            text-decoration: underline;
            color: #5a7df5; /* 稍微深一点的蓝色 */
        }
    </style>
</head>
<body>
    <div id="app">
        <register-form></register-form>
    </div>

    <script>
        Vue.component('register-form', {
            template: `
                <section>
                    <div class="color"></div>
                    <div class="color"></div>
                    <div class="color"></div>
                    <div class="box">
                        <div class="square" style="--i:0;"></div>
                        <div class="square" style="--i:1;"></div>
                        <div class="square" style="--i:2;"></div>
                        <div class="square" style="--i:3;"></div>
                        <div class="square" style="--i:4;"></div>
                        <div class="container">
                            <div class="form">
                                <h2>{{ title }}</h2>
                                <form @submit.prevent="handleSubmit">
                                    <div class="inputBox">
                                        <input 
                                            type="text" 
                                            placeholder="用户名" 
                                            v-model="username"
                                            :class="{'error': errors.username}"
                                            @focus="clearError('username')"
                                        >
                                    </div>
                                    <div v-if="errors.username" class="error-message">{{ errors.username }}</div>
                                    
                                    <div class="inputBox">
                                        <input 
                                            type="email" 
                                            placeholder="电子邮箱" 
                                            v-model="email"
                                            :class="{'error': errors.email}"
                                            @focus="clearError('email')"
                                        >
                                    </div>
                                    <div v-if="errors.email" class="error-message">{{ errors.email }}</div>
                                    
                                    <div class="inputBox">
                                        <input 
                                            type="password" 
                                            placeholder="密码" 
                                            v-model="password"
                                            :class="{'error': errors.password}"
                                            @focus="clearError('password')"
                                        >
                                    </div>
                                    <div v-if="errors.password" class="error-message">{{ errors.password }}</div>
                                    
                                    <div class="inputBox">
                                        <input 
                                            type="password" 
                                            placeholder="确认密码" 
                                            v-model="confirmPassword"
                                            :class="{'error': errors.confirmPassword}"
                                            @focus="clearError('confirmPassword')"
                                        >
                                    </div>
                                    <div v-if="errors.confirmPassword" class="error-message">{{ errors.confirmPassword }}</div>
                                    
                                    <div class="agreement">
                                        <input type="checkbox" id="agreement" v-model="agreedToTerms">
                                        <label for="agreement">我已阅读并同意<a href="#">《用户协议》</a>和<a href="#">《隐私政策》</a></label>
                                    </div>
                                    <div v-if="errors.agreedToTerms" class="error-message">{{ errors.agreedToTerms }}</div>
                                    
                                    <div class="inputBox">
                                        <input type="submit" :value="isLoading ? '注册中...' : '注册'" :disabled="isLoading">
                                    </div>
                                    
                                    <div v-if="successMessage" class="success-message">{{ successMessage }}</div>
                                    
                                    <p class="forget">已有账号?<a href="login.html" @click.prevent="switchToLogin">立即登录</a></p>
                                </form>
                            </div>
                        </div>
                    </div>
                </section>
            `,
            data() {
                return {
                    title: '注册新账号',
                    username: '',
                    email: '',
                    password: '',
                    confirmPassword: '',
                    agreedToTerms: false,
                    errors: {
                        username: '',
                        email: '',
                        password: '',
                        confirmPassword: '',
                        agreedToTerms: ''
                    },
                    isLoading: false,
                    successMessage: ''
                };
            },
            methods: {
                validateForm() {
                    let isValid = true;
                    this.errors = { 
                        username: '', 
                        email: '', 
                        password: '', 
                        confirmPassword: '',
                        agreedToTerms: '' 
                    };
                    
                    // 用户名验证
                    if (!this.username) {
                        this.errors.username = '请输入用户名';
                        isValid = false;
                    } else if (this.username.length != 11) {
                        this.errors.username = '请输入11位学号';
                        isValid = false;
                    }
                    
                    // 邮箱验证
                    if (!this.email) {
                        this.errors.email = '请输入电子邮箱';
                        isValid = false;
                    } else if (!this.isValidEmail(this.email)) {
                        this.errors.email = '请输入有效的电子邮箱';
                        isValid = false;
                    }
                    
                    // 密码验证
                    if (!this.password) {
                        this.errors.password = '请输入密码';
                        isValid = false;
                    } else if (this.password.length < 6) {
                        this.errors.password = '密码长度不能少于6位';
                        isValid = false;
                    }
                    
                    // 确认密码验证
                    if (!this.confirmPassword) {
                        this.errors.confirmPassword = '请确认密码';
                        isValid = false;
                    } else if (this.password !== this.confirmPassword) {
                        this.errors.confirmPassword = '两次输入的密码不一致';
                        isValid = false;
                    }
                    
                    // 协议同意验证
                    if (!this.agreedToTerms) {
                        this.errors.agreedToTerms = '请阅读并同意用户协议和隐私政策';
                        isValid = false;
                    }
                    
                    return isValid;
                },
                
                isValidEmail(email) {
                    const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
                    return re.test(email);
                },
                
                clearError(field) {
                    this.errors[field] = '';
                },
                
                handleSubmit() {
                    if (this.validateForm()) {
                        this.isLoading = true;
                        
                        // 模拟API调用
                        setTimeout(() => {
                            this.isLoading = false;
                            
                            // 检查用户名是否已存在
                            const registeredUsers = JSON.parse(localStorage.getItem('registeredUsers') || '[]');
                            const userExists = registeredUsers.some(user => user.username === this.username);
                            
                            if (userExists) {
                                this.errors.username = '该用户名已被注册';
                                return;
                            }
                            
                            // 检查邮箱是否已存在
                            const emailExists = registeredUsers.some(user => user.email === this.email);
                            
                            if (emailExists) {
                                this.errors.email = '该邮箱已被注册';
                                return;
                            }
                            
                            // 保存用户信息
                            const newUser = {
                                username: this.username,
                                email: this.email,
                                password: this.password,
                                registerTime: new Date().toISOString()
                            };
                            
                            registeredUsers.push(newUser);
                            localStorage.setItem('registeredUsers', JSON.stringify(registeredUsers));
                            
                            // 自动登录
                            localStorage.setItem('currentUser', JSON.stringify({
                                username: this.username
                            }));
                            
                            this.successMessage = '注册成功！正在跳转到首页...';
                            
                            // 跳转到首页
                            setTimeout(() => {
                                window.location.href = 'forum.html';
                            }, 1500);
                        }, 1500);
                    }
                },
                
                switchToLogin() {
                    window.location.href = 'login.html';
                }
            }
        });

        new Vue({
            el: '#app'
        });
    </script>
</body>
</html>